export function FormValidate (refs) {
  return function (target, key, descriptor) {
    if (descriptor.value) {
      const fn = descriptor.value
      descriptor.value = function (vm, ...args) {
        Promise.all(
          refs.reduce((list, key) => {
            return list.concat(vm.$refs[key])
          }, [])
            .filter(obj => obj && obj.validate)
            .map(obj => obj.validate())
        ).then(() => {
          fn.apply(vm, args)
        })
      }
    }
  }
}
/** 时间格式 **/
export function FormatDateTime (newTime) {
  return `${newTime.slice(0, 4)}-${newTime.slice(4, 6)}-${newTime.slice(6, 8)} ${newTime.slice(8, 10)}:${newTime.slice(10, 12)}:${newTime.slice(12, 14)}`
}
/** 审核状态 **/
export function UserStateFilter (userState) {
  var userStateType = ''
  switch (userState) {
    case '00':
      userStateType = '正常'
      break
    case '01':
      userStateType = '等待审核'
      break
    case '02':
      userStateType = '注销'
      break
    case '98':
      userStateType = '待实名认证'
      break
    default:
      userStateType = ''
      break
  }
  return userStateType
}
/** 用户权限状态 **/
export function UserAdmin (userAdState) {
  var userStateType = ''
  switch (userAdState) {
    case 'admin':
      userStateType = '管理者'
      break
    case 'editor':
      userStateType = '普通员工'
      break
    default:
      userStateType = ''
      break
  }
  return userStateType
}
/** 手机号码脱敏 **/
export function hidePhone (phone) {
  return `${phone.slice(0, 3)}****${phone.slice(phone.length - 4)}`
}